package cn.csdj.sism.web;

import cn.csdj.sism.pojo.Payment;
import cn.csdj.sism.pojo.PaymentType;
import cn.csdj.sism.service.PaymentService;
import cn.csdj.sism.service.PaymentTypeService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * @author 李加
 * 2023/4/10
 */
@CrossOrigin
@RestController
@RequestMapping("/payType")
public class PaymentTypeController {
    @Autowired
    private PaymentTypeService paymentTypeService;

    /**
     * 查询全部
     * @return
     */
    @GetMapping
    public List<PaymentType> selectPetAll(){
        return paymentTypeService.selectPmtAll();
    }
    /**
     * 通过Id查询
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public PaymentType selectPetById(@PathVariable Integer id){
        return paymentTypeService.selectPmtById(id);
    }
    /**
     * 添加
     * @param paymentType
     */
    @PostMapping
    public int insertPet(@RequestBody PaymentType paymentType){
        //如果为空就是添加
        if (StringUtils.isEmpty(paymentType.getPmTypeId())){
            return   paymentTypeService.insertPmt(paymentType);
        }else {
//            如果有值就是修改
            return paymentTypeService.updatePmt(paymentType);
        }

    }

    /**
     * 修改
     * @param paymentType
     */
    @PutMapping
    public int updatePet(@RequestBody PaymentType paymentType){
       return paymentTypeService.updatePmt(paymentType);
    }

    /**
     * 删除
     * @param id
     */
    @DeleteMapping("/{id}")
    public int delectPet(@PathVariable Integer id){
       return paymentTypeService.delectPmtById(id);
    }
    @GetMapping("/page/{current}/{pageSize}")
    public IPage<PaymentType> selectPage(@PathVariable Integer current,@PathVariable Integer pageSize){
        return paymentTypeService.page(current,pageSize);
    }
}
